{
  "cells": [
    {
      "cell_type": "markdown",
      "id": "693d9912-8d56-46a2-a445-3ee5651fe433",
      "metadata": {
        "id": "693d9912-8d56-46a2-a445-3ee5651fe433"
      },
      "source": [
        "# Multiple Schemas\n",
        "\n",
        "## Review\n",
        "\n",
        "We just covered state schema and reducers.\n",
        "\n",
        "Typically, all graph nodes communicate with a single schema.\n",
        "\n",
        "Also, this single schema contains the graph's input and output keys / channels.\n",
        "\n",
        "## Goals\n",
        "\n",
        "But, there are cases where we may want a bit more control over this:\n",
        "\n",
        "* Internal nodes may pass information that is *not required* in the graph's input / output.\n",
        "\n",
        "* We may also want to use different input / output schemas for the graph. The output might, for example, only contain a single relevant output key.\n",
        "\n",
        "We'll discuss a few ways to customize graphs with multiple schemas."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 20,
      "id": "4d727cc2-5a43-4eb5-9d69-82bbbcc35bd9",
      "metadata": {
        "id": "4d727cc2-5a43-4eb5-9d69-82bbbcc35bd9"
      },
      "outputs": [],
      "source": [
        "%%capture --no-stderr\n",
        "%pip install --quiet -U langgraph"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Simple State"
      ],
      "metadata": {
        "id": "mWc6ZLHYtqf_"
      },
      "id": "mWc6ZLHYtqf_"
    },
    {
      "cell_type": "code",
      "source": [
        "from typing_extensions import TypedDict\n",
        "from IPython.display import Image, display\n",
        "from langgraph.graph import StateGraph, START, END\n",
        "from langgraph.graph.state import CompiledStateGraph\n",
        "\n",
        "class OverallState(TypedDict):\n",
        "    foo: int\n",
        "    baz: int\n",
        "\n",
        "def node_1(state: OverallState) -> OverallState:\n",
        "    print(\"---Node 1---\")\n",
        "    return {\"baz\": state['foo'] + 1}\n",
        "\n",
        "def node_2(state: OverallState) -> OverallState:\n",
        "    print(\"---Node 2---\")\n",
        "    return {\"foo\": state['baz'] + 1}\n",
        "\n",
        "# Build graph\n",
        "builder: StateGraph = StateGraph(OverallState)\n",
        "builder.add_node(\"node_1\", node_1)\n",
        "builder.add_node(\"node_2\", node_2)\n",
        "\n",
        "# Logic\n",
        "builder.add_edge(START, \"node_1\")\n",
        "builder.add_edge(\"node_1\", \"node_2\")\n",
        "builder.add_edge(\"node_2\", END)\n",
        "\n",
        "# Add\n",
        "graph: CompiledStateGraph = builder.compile()\n",
        "\n",
        "# View\n",
        "display(Image(graph.get_graph().draw_mermaid_png()))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 350
        },
        "id": "ZLSyz5tftqSL",
        "outputId": "34a57bc5-fdab-4bc1-d02f-eae62adca80f"
      },
      "id": "ZLSyz5tftqSL",
      "execution_count": 21,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWFlaAAABKAAAABRiWFlaAAABPAAAABR3dHB0AAABUAAAABRyVFJDAAABZAAAAChnVFJDAAABZAAAAChiVFJDAAABZAAAAChjcHJ0AAABjAAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJYWVogAAAAAAAAb6IAADj1AAADkFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAACSgAAAPhAAAts9YWVogAAAAAAAA9tYAAQAAAADTLXBhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABtbHVjAAAAAAAAAAEAAAAMZW5VUwAAACAAAAAcAEcAbwBvAGcAbABlACAASQBuAGMALgAgADIAMAAxADb/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYI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ECOiLEYTyttNjQHXZP1kkkknqSST1NdulebabZOtW9iw0+gFKUriIf/Z\n",
            "text/plain": [
              "<IPython.core.display.Image object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "graph.invoke({\"foo\" : 1})"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "nFpIuXVStwyo",
        "outputId": "1ebd8d7b-ade7-42fe-9e69-f26cb4e1de25"
      },
      "id": "nFpIuXVStwyo",
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "---Node 1---\n",
            "---Node 2---\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'foo': 3, 'baz': 2}"
            ]
          },
          "metadata": {},
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "markdown",
      "id": "29b3d109-6bf2-4271-9775-556ee4bd900d",
      "metadata": {
        "id": "29b3d109-6bf2-4271-9775-556ee4bd900d"
      },
      "source": [
        "## Private State\n",
        "\n",
        "First, let's cover the case of passing [private state](https://langchain-ai.github.io/langgraph/how-tos/pass_private_state/) between nodes.\n",
        "\n",
        "This is useful for anything needed as part of the intermediate working logic of the graph, but not relevant for the overall graph input or output.\n",
        "\n",
        "We'll define an `OverallState` and a `PrivateState`.\n",
        "\n",
        "`node_2` uses `PrivateState` as input, but writes out to `OverallState`."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 23,
      "id": "038ca2e4-7d6d-49d5-b213-b38469cde434",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 350
        },
        "id": "038ca2e4-7d6d-49d5-b213-b38469cde434",
        "outputId": "9be418e6-8a7f-4d3a-ac56-df6ab8c703c9"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWi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ArICeQBzp545fN87fTp2V1bhh1guzUJudY7bNbhACKiREbcEcAAANgjzdADs12VrdkdaqmbbWuLePdX0BTvc46+BLE+U7T72Vo7308IutIqqTMIlILLNjyKZi9tZbCG7da4cMMI6kkgLYURvfYDr6q6/kRkP+0O++p2//ALaumXelQQwXW6JL6dQXOuvOC1Mtpa34ZTzSW9dvOXEhP/PVdPHrTNs8Vxqde5l9cUvmS9MaYbUgaHmgNNoGu/qCevbV64aYs5lOUxpSkE2u1Oh91wjot9Oi22D3kHSz8nKn+9VmzoZMpzY8Ev8AaFhzPQFKUr8vKKUpQGd5hwdiXuW9cLTK8TznVFbrfgg5HeWe1SkbBSonqVJI2SSQondUh3hHmLKiAxaZA7ltzVp39oLXT/E1vdK9eT7VtMmG4nVLUtdTAPgozL5jbfX1ezp8FGZfMbb6+r2db/Suj41adFyfUYaGAfBRmXzG2+vq9nT4KMy+Y2319Xs63+lPjVp0XJ9RhoYB8FGZfMbb6+r2dfo4UZkTr3lbB9Znq1/CrfqU+NWnRcv7GGhjdk4H3KS6ld8ubMVgEExrXtal/UXVpGh9iN/IRWs2q0w7HbmIECOiLEYTyttNjQHXZP1kkkknqSST1NdulebabZOtW9iw0+gFKUriIf/Z\n",
            "text/plain": [
              "<IPython.core.display.Image object>"
            ]
          },
          "metadata": {}
        }
      ],
      "source": [
        "from typing_extensions import TypedDict\n",
        "from IPython.display import Image, display\n",
        "from langgraph.graph import StateGraph, START, END\n",
        "from langgraph.graph.state import CompiledStateGraph\n",
        "\n",
        "class OverallState(TypedDict):\n",
        "    foo: int\n",
        "\n",
        "class PrivateState(TypedDict):\n",
        "    baz: int\n",
        "\n",
        "def node_1(state: OverallState) -> PrivateState:\n",
        "    print(\"---Node 1---\")\n",
        "    return {\"baz\": state['foo'] + 1}\n",
        "\n",
        "def node_2(state: PrivateState) -> OverallState:\n",
        "    print(\"---Node 2---\")\n",
        "    return {\"foo\": state['baz'] + 1}\n",
        "\n",
        "# Build graph\n",
        "builder: StateGraph = StateGraph(OverallState)\n",
        "builder.add_node(\"node_1\", node_1)\n",
        "builder.add_node(\"node_2\", node_2)\n",
        "\n",
        "# Logic\n",
        "builder.add_edge(START, \"node_1\")\n",
        "builder.add_edge(\"node_1\", \"node_2\")\n",
        "builder.add_edge(\"node_2\", END)\n",
        "\n",
        "# Add\n",
        "graph: CompiledStateGraph = builder.compile()\n",
        "\n",
        "# View\n",
        "display(Image(graph.get_graph().draw_mermaid_png()))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 24,
      "id": "3dc9cd64-4bd3-4c0a-8f8f-d58c551428e3",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "3dc9cd64-4bd3-4c0a-8f8f-d58c551428e3",
        "outputId": "49a99986-1d7a-4628-e4ef-824c1cfcec56"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "---Node 1---\n",
            "---Node 2---\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'foo': 3}"
            ]
          },
          "metadata": {},
          "execution_count": 24
        }
      ],
      "source": [
        "graph.invoke({\"foo\" : 1})"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "50a29f37-f653-4a56-ad0a-345d7f632ea0",
      "metadata": {
        "id": "50a29f37-f653-4a56-ad0a-345d7f632ea0"
      },
      "source": [
        "`baz` is only included in `PrivateState`.\n",
        "\n",
        "`node_2` uses `PrivateState` as input, but writes out to `OverallState`.\n",
        "\n",
        "So, we can see that `baz` is excluded from the graph output because it is not in `OverallState`."
      ]
    },
    {
      "cell_type": "markdown",
      "id": "75a8362f-009b-4ec2-abe5-8fb318e39966",
      "metadata": {
        "id": "75a8362f-009b-4ec2-abe5-8fb318e39966"
      },
      "source": [
        "## Input / Output Schema\n",
        "\n",
        "By default, `StateGraph` takes in a single schema and all nodes are expected to communicate with that schema.\n",
        "\n",
        "However, it is also possible to [define explicit input and output schemas for a graph](https://langchain-ai.github.io/langgraph/how-tos/input_output_schema/?h=input+outp).\n",
        "\n",
        "Often, in these cases, we define an \"internal\" schema that contains *all* keys relevant to graph operations.\n",
        "\n",
        "But, we use specific `input` and `output` schemas to constrain the input and output.\n",
        "\n",
        "First, let's just run the graph with a single schema."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 25,
      "id": "5323068a-907a-438c-8db5-46e5d452ad72",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 350
        },
        "id": "5323068a-907a-438c-8db5-46e5d452ad72",
        "outputId": "d33f5d70-2b6b-4d16-c6ef-42e3b8a1ad97"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWFlaAAABKAAAABRiWFlaAAABPAAAABR3dHB0AAABUAAAABRyVFJDAAABZAAAAChnVFJDAAABZAAAAChiVFJDAAABZAAAAChjcHJ0AAABjAAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJYWVogAAAAAAAAb6IAADj1AAADkFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAACSgAAAPhAAAts9YWVogAAAAAAAA9tYAAQAAAADTLXBhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABtbHVjAAAAAAAAAAEAAAAMZW5VUwAAACAAAAAcAEcAbwBvAGcAbABlACAASQBuAGMALgAgADIAMAAxADb/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQ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j6jDIwan4P5fUPAkbaaNnpkdVSSkdfQ0Rjf/qC0LCuFdBidS2vqZ3Xa7NBDKiVgYyDY0eyYN8ux02S52iRvR0rui8s/4ntO0Q2InRPL7qPIIiLlEBERAEREB//Z\n",
            "text/plain": [
              "<IPython.core.display.Image object>"
            ]
          },
          "metadata": {}
        }
      ],
      "source": [
        "class OverallState(TypedDict):\n",
        "    question: str\n",
        "    answer: str\n",
        "    notes: str\n",
        "\n",
        "def thinking_node(state: OverallState) -> OverallState:\n",
        "    return {\"answer\": \"bye\", \"notes\": \"... his is name is Lance\"}\n",
        "\n",
        "def answer_node(state: OverallState) -> OverallState:\n",
        "    return {\"answer\": \"bye Lance\"}\n",
        "\n",
        "graph: StateGraph = StateGraph(OverallState)\n",
        "graph.add_node(\"answer_node\", answer_node)\n",
        "graph.add_node(\"thinking_node\", thinking_node)\n",
        "graph.add_edge(START, \"thinking_node\")\n",
        "graph.add_edge(\"thinking_node\", \"answer_node\")\n",
        "graph.add_edge(\"answer_node\", END)\n",
        "\n",
        "graph: CompiledStateGraph = graph.compile()\n",
        "\n",
        "# View\n",
        "display(Image(graph.get_graph().draw_mermaid_png()))"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "853fc90c-bf82-4d51-b3a5-ceb0b0ae5233",
      "metadata": {
        "id": "853fc90c-bf82-4d51-b3a5-ceb0b0ae5233"
      },
      "source": [
        "Notice that the output of invoke contains all keys in `OverallState`."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 26,
      "id": "507d35e6-f65c-4e89-b26e-a0ef7b90be83",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "507d35e6-f65c-4e89-b26e-a0ef7b90be83",
        "outputId": "8c9634d9-5a9d-450e-8498-e462980c1fea"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'question': 'hi', 'answer': 'bye Lance', 'notes': '... his is name is Lance'}"
            ]
          },
          "metadata": {},
          "execution_count": 26
        }
      ],
      "source": [
        "graph.invoke({\"question\":\"hi\"})"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "e5a899c3-e1b0-48eb-9a36-8c787e378ef0",
      "metadata": {
        "id": "e5a899c3-e1b0-48eb-9a36-8c787e378ef0"
      },
      "source": [
        "Now, let's use a specific `input` and `output` schema with our graph.\n",
        "\n",
        "Here, `input` / `output` schemas perform *filtering* on what keys are permitted on the input and output of the graph.\n",
        "\n",
        "In addition, we can use a type hint `state: InputState` to specify the input schema of each of our nodes.\n",
        "\n",
        "This is important when the graph is using multiple schemas.\n",
        "\n",
        "We use type hints below to, for example, show that the output of `answer_node` will be filtered to `OutputState`."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 27,
      "id": "682b3d10-c78a-41c2-a5ff-842e1688c95f",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 367
        },
        "id": "682b3d10-c78a-41c2-a5ff-842e1688c95f",
        "outputId": "ff380da0-9e2e-4715-f963-91409855607d"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWFlaAAABKAAAABRiWFlaAAABPAAAABR3dHB0AAABUAAAABRyVFJDAAABZAAAAChnVFJDAAABZAAAAChiVFJDAAABZAAAAChjcHJ0AAABjAAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJYWVogAAAAAAAAb6IAADj1AAADkFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAACSgAAAPhAAAts9YWVogA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IgCIiAIiICMyLG7flVtdQ3KATwlwe0g6fG8dz2OHVrhs9R6yO4kLJ7twSvlHIfBNyo7lB/otuJdBKOvpexrmuOvU1q2tF79m26fsuEuLDLgTUwDyUZl9Btvv7vhp5KMy+g23393w1v6LofnW05LT/owyMA8lGZfQbb7+74aeSjMvoNt9/d8Nb+ifnW05LR9RhkYB5KMy+g23393w08lGZfQbb7+74a39E/OtpyWj6jDIwan4P5fUPAkbaaNnpkdVSSkdfQ0Rjf/qC0LCuFdBidS2vqZ3Xa7NBDKiVgYyDY0eyYN8ux02S52iRvR0rui8s/4ntO0Q2InRPL7qPIIiLlEBERAEREB//Z\n",
            "text/plain": [
              "<IPython.core.display.Image object>"
            ]
          },
          "metadata": {}
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'answer': 'bye Lance'}"
            ]
          },
          "metadata": {},
          "execution_count": 27
        }
      ],
      "source": [
        "class InputState(TypedDict):\n",
        "    question: str\n",
        "\n",
        "class OutputState(TypedDict):\n",
        "    answer: str\n",
        "\n",
        "class OverallState(TypedDict):\n",
        "    question: str\n",
        "    answer: str\n",
        "    notes: str\n",
        "\n",
        "def thinking_node(state: InputState):\n",
        "    return {\"answer\": \"bye\", \"notes\": \"... his is name is Lance\"}\n",
        "\n",
        "def answer_node(state: OverallState):\n",
        "    return {\"answer\": \"bye Lance\"}\n",
        "\n",
        "graph: StateGraph = StateGraph(OverallState, input=InputState, output=OutputState)\n",
        "graph.add_node(\"answer_node\", answer_node)\n",
        "graph.add_node(\"thinking_node\", thinking_node)\n",
        "graph.add_edge(START, \"thinking_node\")\n",
        "graph.add_edge(\"thinking_node\", \"answer_node\")\n",
        "graph.add_edge(\"answer_node\", END)\n",
        "\n",
        "graph: CompiledStateGraph = graph.compile()\n",
        "\n",
        "# View\n",
        "display(Image(graph.get_graph().draw_mermaid_png()))\n",
        "\n",
        "graph.invoke({\"question\":\"hi\"})"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "f1e5ff21",
      "metadata": {
        "id": "f1e5ff21"
      },
      "source": [
        "We can see the `output` schema constrains the output to only the `answer` key."
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3 (ipykernel)",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.3"
    },
    "colab": {
      "provenance": []
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}